/*
 * 路由配置
 * @Author: ljb
 * @Date: 2018-11-13 14:50:00
 * @Last Modified by: ljb
 * @Last Modified time: 2019-01-25 09:56:45
 */
import VueRouter from 'vue-router';
import { $t } from 'src/i18n';
import handleRouter from './handleRouter';
import debugRouter from './debug-router';

const routers = [
	{
		path: '/',
		name: 'index',
		meta: {
			title: $t('routers.home'),
		},
		component(resolve) {
			return require.ensure([], () => resolve(require('./views/index.vue')), 'index');
		},
	},
	{
		path: '/discovery',
		name: 'discovery',
		meta: {
			title: $t('routers.discovery'),
		},
		component: resolve => require.ensure([], () => resolve(require('./views/discovery.vue')), 'discovery'),
	},
	{
		path: '/article-detail',
		name: 'article-detail',
		meta: {
			title: $t('routers.article_detail'),
		},
		component: resolve => require.ensure([], () => resolve(require('./views/article-detail.vue')), 'article-detail'),
	},
	{
		path: '/more',
		name: 'more',
		meta: {
			title: $t('routers.more'),
		},
		component: resolve => require.ensure([], () => resolve(require('./views/more/views.vue')), 'more'),
	},
	{
		path: '/agreement',
		name: 'more',
		meta: {
			title: $t('routers.agreement'),
		},
		component: resolve => require.ensure([], () => resolve(require('./views/agreement/views.vue')), 'agreement'),
	},
	{
		path: '*',
		redirect: { name: 'index' },
	},
];

// 路由配置
const RouterConfig = {
	// mode: 'history',
	mode: 'hash',
	routes: routers.concat(debugRouter),
};

const router = new VueRouter(RouterConfig);

router.beforeEach(handleRouter.before);
router.afterEach(handleRouter.after);

export default router;
